<template>
  <ComForm
    ref="formRef"
    :format="format"
    @submit="submit"
    @reset="reset"
    class="form"
  ></ComForm>
  <ComTable
    :cell-style="{ height: '50px' }"
    ref="tableRef"
    :column="column"
    :api="listPost"
    :where="where"
    :isSelection="true"
    @approve="approve"
  ></ComTable>
  <Pop ref="popRef" title="审核" width="500px" @confirm="confirm">
    <ComForm ref="editFormRef" :format="editFormat"></ComForm>
  </Pop>
</template>
  <script lang="ts" setup>
import { ref } from "vue";
import { listPost } from "@/api/system/post";

const editFormRef = ref(null);
const popRef = ref(null);
//表格相关配置
const tableRef = ref();
let column = ref([
  { label: "请假人", prop: "postId" },
  { label: "请假类型", prop: "postCode" },
  { label: "开始时间", prop: "postName" },
  { label: "结束时间", prop: "postSort" },
  { label: "审批人", prop: "postId" },
  { label: "申请时间", prop: "postId" },
  { label: "备注", prop: "postId" },
  {
    label: "操作",
    btns: [
      {
        title: "审批",
        disabled: (data) => (data.postCode == 1 ? true : false),
        event: "approve",
      },
    ],
  },
]);
const where = ref({});
const edit = (e) => {
  console.log("编辑", e);
};
const getSelectionRows = () => {
  console.log(tableRef.value.getSelectable());
};
// 表单相关配置
const format = ref([
  {
    label: "请假人",
    prop: "postCode",
    type: "input",
    span: 5,
  },
  {
    label: "审核状态",
    prop: "status",
    type: "select",
    option: [
      { label: 0, value: 0 },
      { label: 1, value: 1 },
    ],
    validate: "required",
    span: 5,
  },
  {
    label: "请假类型",
    prop: "status",
    type: "select",
    option: [
      { label: 0, value: 0 },
      { label: 1, value: 1 },
    ],
    span: 5,
  },
  {
    label: "",
    prop: "",
    type: "button",
    btns: [
      { label: "查询", event: "submit", type: "success" },
      { label: "重置", event: "reset" },
    ],
    span: 8,
  },
]);
const formRef = ref(null);
const submit = (data: any) => {
  formRef.value.checkForm().then((result) => {
    if (result) {
      //内部执行提交逻辑
    }
  });
};
const reset = (data: any) => {
  console.log(data);
  formRef.value.reset();
};
const approve = (e) => {
  popRef.value.show();
};
const editFormat = ref([
  {
    label: "是否通过",
    prop: "postCode",
    type: "radio",
    defaultValue: 0,
    option: [
      { label: "是", value: 0 },
      { label: "否", value: 1 },
    ],
    rules: [
      {
        required: true,
        trigger: "blur",
        message: "请选择是否通过",
      },
    ],
    span: 24,
  },
  {
    label: "意见",
    prop: "xxxxx",
    type: "textarea",
    span: 24,
  },
]);
const confirm = () => {
  editFormRef.value.checkForm().then((result) => {
    if (result) {
      //内部执行提交逻辑
      console.log(editFormRef.value.getFormItem());
    }
  });
};
</script>
  <style scoped>
.form {
  padding: 20px 20px;
}
</style>